package com.yun.algorithmproblem.leetcode;

public class Leetcode714_SharesIII {
    public int maxProfit(int[] prices, int fee) {
        //_buy _sell _buy sell
//        int[] dpBuy=new int[prices.length];
//        int[] dpSell=new int[prices.length];
//        dpBuy[0]=-prices[0];
//        dpSell[0]=0;
        int buy = -prices[0];
        int sell = 0;
        for (int i = 1; i < prices.length; i++) {
            buy = Math.max(buy, sell - prices[i]);
            /*
                这次buy的两种情况
                    就是上次buy
                    sell-prices[i]
             */
            sell = Math.max(sell, buy + prices[i] - fee);
        }
        return sell;
    }

    public static void main(String[] args) {
        int[] prices = {1, 3, 2, 8, 4, 9};
        int[] prices2 = {3, 3};
        Leetcode714_SharesIII test = new Leetcode714_SharesIII();
        System.out.println(test.maxProfit(prices, 2));
    }
}
